﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace Team4Mock.DAO
{
    public class TrustRegionDAO
    {
        Helper h = new Helper();
        public DataTable Search(string key)
        {
            SqlParameter[] p;
            p = new SqlParameter[1];
            p[0] = new SqlParameter("@key", key);
            p[0].SqlDbType = SqlDbType.VarChar;
            return h.GetData("TrustRegion_Search",p);
        }
        public DataTable Getdata()
        {
            return h.GetData("TrustRegion_Getdata");
        }
        public DataTable GetdataByID(int id)
        {
            SqlParameter[] p;
            p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("TrustRegion_GetdataByID",p);
        }
        //TrustRegion_GetdataByID
        public  DataTable GetDataTrue()
        {
            return h.GetData("TrustRegion_GetdataTrue");
        }
        public void Insert(string name,string des,string country,int active)
        {
            SqlParameter[] p;
            p = new SqlParameter[4];
            p[0] = new SqlParameter("@name", name);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@des", des);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@country", country);
            p[2].SqlDbType = SqlDbType.VarChar;
            p[3] = new SqlParameter("@active", active);
            p[3].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("TrustRegion_Insert",p);
        }
        public void Update(string name, string des, string country, int active,int id)
        {
            SqlParameter[] p;
            p = new SqlParameter[5];
            p[0] = new SqlParameter("@name", name);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@des", des);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@country", country);
            p[2].SqlDbType = SqlDbType.VarChar;
            p[3] = new SqlParameter("@active", active);
            p[3].SqlDbType = SqlDbType.Int;
            p[4] = new SqlParameter("@id", id);
            p[4].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("TrustRegion_Update", p);
        }
        public DataTable GetDistrictById(int id)
        {
            SqlParameter[] p;
            p = new SqlParameter[1];
            p[0] = new SqlParameter("@iddis", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("TrustRegion_GetDistrictByID", p);
        }
    }
}